package com.by.yz.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.by.yz.App;
import com.by.yz.R;
import com.by.yz.activity.base.BaseActivity;
import com.by.yz.chatuidemo.Constant;
import com.by.yz.chatuidemo.ui.ChatActivity;
import com.by.yz.custom.CircleNetworkImageView;
import com.by.yz.entity.Doctorbean;
import com.by.yz.entity.UserTest;
import com.by.yz.loginUtil.UserRESTFul;
import com.by.yz.util.ToJSonObject;
import com.hyphenate.chat.EMClient;
import com.hyphenate.easeui.widget.EaseAlertDialog;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by 你只能呵呵 on 2016/10/15.
 */

public class ConsuiltActivity extends BaseActivity {

    Button buy_now;
    TextView  doctorName,position,hospital,department;
    CircleNetworkImageView headimg;
    String nickname="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tuwenzixun);
        setToolbarTitle("图文咨询");
        Intent intent = this.getIntent();
        final Doctorbean team=(Doctorbean)intent.getSerializableExtra("doctorid");
        UserRESTFul userRESTFul=new UserRESTFul();
        userRESTFul.getUser(team.getLogin(), new UserRESTFul.UserPOSTCallBack() {
            @Override
            public void ok(JSONObject response) throws JSONException {
                UserTest userTest;
                JSONObject jsonObject=response;
                userTest= ToJSonObject.jsonToBean(jsonObject.toString(),UserTest.class);
                nickname = userTest.getnickName().toString();
                Log.e("userName = ",nickname+"");
            }
            @Override
            public void error(String response) {
                Log.e("PCF-user-error","获取用户表失败"+response);
            }
        });
        doctorName=(TextView)findViewById(R.id.famous_doctor_name_textview);
        doctorName.setText(team.getDoctorname());
        position=(TextView)findViewById(R.id.touxian_textview);
        position.setText(team.getPosition());
        hospital=(TextView)findViewById(R.id.hospital_textview);
        hospital.setText(team.getTextHospital().getHospital());
        department=(TextView)findViewById(R.id.keshi_textview);
        department.setText(team.getDepartment().getDepartment());
        headimg=(CircleNetworkImageView)findViewById(R.id.famous_doctor_image);
        headimg.setDefaultImageResId(R.mipmap.login_logo1);
        headimg.setErrorImageResId(R.mipmap.login_error);
        headimg.setImageUrl(team.getmImageView(), App.imageLoader);
        buy_now=(Button)findViewById(R.id.buy_now);
        Log.e("userId",team.getLogin()+"");
        buy_now.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(EMClient.getInstance().getCurrentUser().equals(team.getLogin())){
                    new EaseAlertDialog(ConsuiltActivity.this, "不能和自己聊天").show();
                    return;
                }
                Intent intent=new Intent(ConsuiltActivity.this,ChatActivity.class);
                intent.putExtra(Constant.EXTRA_USER_ID,team.getLogin().toString());
                intent.putExtra("userName", nickname);
                startActivity(intent);
            }
        });
    }
}
